﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace Exercises
{
    class InheritedEmployee : Employee
    {
        private EntitySet<Territory> territories = new EntitySet<Territory>();

        public EntitySet<Territory> Territories
        {
            get 
            {
                this.territories.Clear();
                EntitySet<Territory> ter = new EntitySet<Territory>();
                DataClassNorthwindDataContext context = new DataClassNorthwindDataContext();
                var res =
                    from employeeTer in context.EmployeeTerritories
                    join terr in context.Territories on employeeTer.TerritoryID equals terr.TerritoryID
                    where employeeTer.EmployeeID == this.EmployeeID
                    select terr;
                foreach (var item in res)
                {
                    this.territories.Add(item);
                }
                return territories; 
            }           
        }

        public InheritedEmployee() : base()
        {
            EntitySet<Territory> ter = new EntitySet<Territory>();
            //DataClassNorthwindDataContext context = new DataClassNorthwindDataContext();
            //var res = 
            //    from employeeTer in context.EmployeeTerritories
            //    join terr in context.Territories on employeeTer.TerritoryID equals terr.TerritoryID
            //    where employeeTer.EmployeeID == this.EmployeeID
            //    select terr;
        }
    }
}
